// const BASE_URL = "http://127.0.0.1:8080";
const BASE_URL = "https://douyin.zshun.top";

export const request = (options) => {
	return new Promise((resolve, reject) => {
		var defaultHeader = {
			"Content-Type": 'application/x-www-form-urlencoded; charset=UTF-8'
		}
		uni.request({
			url: BASE_URL + options.url,
			method: options.method || "GET", // 请求类型，默认为GET
			data: options.data || {}, // 请求参数，默认空对象
			header: options.header || defaultHeader,
			success: res => {
				resolve(res)
			},
			fail: err => {
				uni.showToast({
					title: "请求失败！",
					icon: "none",
					duration: 2000
				})
				reject(err)
			}
		})
	})
}

export const downloadFile = (options) => {
	return new Promise((resolve, reject) => {
		uni.downloadFile({
			url: BASE_URL + options.url,
			success: res => {
				resolve(res)
			},
			fail: err => {
				uni.showToast({
					title: "下载失败！",
					icon: "none",
					duration: 2000
				})
				reject(err)
			}
		})
	})
}
